#ifndef __SPI_Flash_H
#define __SPI_Flash_H


#ifdef __cplusplus
extern "C" {
#endif 
#include "gd32e10x.h"

	//FLASH命令定义
#define Write_Enable       0x06
#define Write_Disable      0x04
#define Page_Program       0x02
#define Read_Data          0x03
#define Sector_Erase       0x20
#define Block_Erase32K     0x52
#define Block_Erase64K     0xd8
#define Power_Down         0xb9
#define ReleasePower_Down  0xab
#define Read_Status_Reg1   0x05
#define Write_Status_Reg   0x01
#define Read_Status_Reg2   0x35
#define Write_Enable_Bit   0x02
#define Busy_Bit           0x01

#define W25Q80_ID 	0XEF13 	
#define W25Q16_ID 	0XEF14
#define W25Q32_ID 	0XEF15
#define W25Q64_ID 	0XEF16
#define W25Q128_ID	0XEF17
#define W25Q256_ID	0XEF18
#define GD25Q256		0xC818	

//#define FLASH_ID  W25Q16_ID//W25Q80_ID//W25Q64_ID ////当前使用FLASH的ID	

void delayAfterSPI_CS_H(void);

#define FLASH_CS_L  gpio_bit_reset(GPIOB, GPIO_PIN_12)
#define FLASH_CS_H  gpio_bit_set(GPIOB, GPIO_PIN_12); delayAfterSPI_CS_H()

	
void SPI1_Configuration(void);
//void SPI0_Configuration(void);
void Flash_WriteRegister(uint8_t Reg1_cmd,uint8_t Reg2_cmd);
void Flash_write_enable(void);
void Flash_write_disable(void);
//uint8_t SPI0_Byte(uint8_t byte);
uint8_t SPI1_Byte(uint8_t byte);
void Flash_Send_Cmd(uint8_t cmd);
void Flash_Send_Dat(uint8_t dat);
void Flash_Write_Byte(uint32_t addr,uint8_t byte);
void Flash_Write_Data(uint32_t addr,uint8_t *buf,uint16_t lenth);

uint8_t Flash_Read_Reg(uint8_t cmd);
uint8_t Flash_Read_Byte(uint32_t addr);
void Flash_Read_Data(uint32_t addr,uint8_t *buf,uint16_t lenth);
void Flash_Erase(uint8_t cmd,uint32_t addr);
uint8_t Flash_Busy(void);
uint8_t Flash_Init(void);

void Flash_EraseAll(uint8_t cmd);
uint8_t getFlashID(void);
uint8_t verifyFlashID(void);

#ifdef __cplusplus
}
#endif


#endif



